package com.hspedu.threaduse;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/15
 * @time 11:34
 */
public class Thread02 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        Thread thread = new Thread(dog);
        thread.start();
    }
}

class Dog implements Runnable{
    int num = 0;
    @Override
    public void run() {
        while (true){
            System.out.println("小狗汪汪叫 "+ Thread.currentThread().getName()+"\t"+(++num));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (num == 10){
                break;
            }
        }
    }
}

/**
 * 模拟Thread类
 */
class ThreadProxy implements Runnable{
    private Runnable target;
    @Override
    public void run() {
        if (target != null){
            target.run();
        }
    }

    public ThreadProxy(Runnable target){
        this.target = target;
    }

    public void start(){
        start0();
    }

    public void start0(){
        run();
    }

}
